<template>
  <div id="guest-book">
    <el-row :gutter="20">
      <el-col :span="16">
        <!-- 添加留言 -->
        <add-guest @getNewList="getGuestList" />
        <div class="guest-list">
          <h2 class="text-align-center p-t-10 p-b-10"><i class="el-icon-back"></i> 留言列表 <i class="el-icon-right"></i></h2>
          <!-- 留言列表 -->
          <div v-if="guestList.length !== 0">
            <div class="guest" v-for="(item, index) in guestList" :key="index">
              <header class="h-40 l-h-40 flex">
                <div class="w-30 m-r-10"><img width="100%" class="border-r" :src="item.guestIcon" alt=""></div>
                <h3 class="color2">{{item.guestName}}</h3>
              </header>
              <div class="content">
                <div>{{item.guestContent}}</div>
                <div v-if="item.isReply" class="reply m-t-10 ">管理员回复: {{item.reply}}</div>
              </div>
              <footer>
                <div class="fz-14"><i class="el-icon-time"></i> {{item.createTime | dateTime}}</div>
              </footer>
            </div>
            <el-pagination
              @size-change="sizeChange"
              @current-change="currentChange"
              :current-page="page.currentPage"
              :page-sizes="pageSizes"
              :page-size="page.pageSize"
              layout="prev, pager, next"
              :total="totalNum" 
              background
              class="flex flex-space-between m-t-15">
            </el-pagination>
          </div>
          <div v-else class="p-t-30 text-align-center">
            <el-divider></el-divider>
            <i class="el-icon-chat-square fz-50"></i>
            <h3>暂无留言</h3>
            <el-divider></el-divider>
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="right">
          <special-recommend class="m-b-50" />
          <LastUpdateArticle />
        </div>
      </el-col>
    </el-row>  
  </div>
</template>

<script>
import SpecialRecommend from '../components/SpecialRecommend'
import LastUpdateArticle from '../components/LastUpdateArticle'
import AddGuest from '../components/AddGuest'
export default {
  components: {
    AddGuest,
    SpecialRecommend,
    LastUpdateArticle
  },
  data() {
    return {
      guestList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
      },
      pageSizes: [10, 20, 30, 40, 50],
      totalNum: 1000
    }
  },
  created() {
    this.getGuestList()
  },
  methods: {
    async getGuestList() {
      let res = await this.api.post('/client/getGuestList', this.page)
      if(res.code == 0) {
        this.guestList = res.data.guestList
        this.totalNum = res.data.counts
        console.log(this.guestList)
      }
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize
      this.getGuestList()
    },
    currentChange(thisPage) {
      this.page.currentPage = thisPage
      this.getGuestList()
    },
  },
}
</script>

<style lang="scss">
#guest-book {
  width: 1100px;
  padding-top: 80px;
  margin: 0 auto;
  .guest-list {
    color: #606266;
    margin-top: 30px;
    border-top: 1px solid #DCDFE6;
    .guest {
      border-bottom: 1px dashed #DCDFE6;
      padding: 18px 0;
      img {
        vertical-align: middle;
      }
      .content {
        padding: 15px 15px;
        border-left: 3px solid #ddd;
        background: #f6f6f6;
        margin: 14px auto;
        .reply {
          color: #fa6706;
        }
      }
    }
  }
}
</style>